// pages/fenLei/fenLei.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:[],
    tabbar:{},
    tabList: [],
    clickId:0
    
  },

  upper(e) {
    console.log(e)
  },

  lower(e) {
    console.log(e)
  },

  scroll(e) {
    console.log(e)
  },

  scrollToTop() {
    this.setAction({
      scrollTop: 0
    })
  },

  tap() {
    for (let i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1],
          scrollTop: (i + 1) * 200
        })
        break
      }
    }
  },

  tapMove() {
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    app.changeTabBar();

    app.util.request({
      url: 'admin/CategoryApi/selectCategory',
      data: {},
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res){
        // console.log(res)
        var value = res.data.value;
        var data = value[0]['son'];
        for(var i=0;i<data.length;i++){
          data[i]['logo'] = app.globalData.url+data[i]['logo'];
        }
        that.setData({
          tabList: res.data.value,
          data: data,
          clickId: value[0]['id']
        })
      }
    });
    
  },
  tabClick:function(e){
    var that = this;
    var data = that.data.tabList;
    for(var i=0;i<data.length;i++){
      if (e.currentTarget.id == data[i]['id']){
        var datas = data[i]['son'];
        for (var d = 0; d < datas.length;d++){
          if(datas[d]['logo'].indexOf("https://") == -1 ){
            datas[d]['logo'] = app.globalData.url + datas[d]['logo'];
          }
        }
        that.setData({
          clickId: e.currentTarget.id,
          data:datas
        })
      }
    }
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})